/*
+--------------------------------------------------------------------------
|   Mblog [#RELEASE_VERSION#]
|   ========================================
|   Copyright (c) 2014, 2015 mtons. All Rights Reserved
|   http://www.mtons.com
|
+---------------------------------------------------------------------------
*/
package com.mtons.mblog.web.controller.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mtons.mblog.base.lang.Result;
import com.mtons.mblog.modules.data.CommentVO;
import com.mtons.mblog.modules.data.PostVO;
import com.mtons.mblog.modules.data.StockVo;
import com.mtons.mblog.modules.service.CommentService;
import com.mtons.mblog.modules.service.PostService;
import com.mtons.mblog.modules.service.StockService;
import com.mtons.mblog.web.controller.BaseController;

/**
 * 侧边栏数据加载
 *
 * @author langhsu
 */
@RestController
@RequestMapping("/api")
public class SidebarController extends BaseController {
	@Autowired
	private PostService postService;
	@Autowired
	private CommentService commentService;
	@Autowired
	private StockService stockService;

	@PostMapping(value = "/login")
	public Result login(String username, String password) {
		return executeLogin(username, password, false);
	}

	@RequestMapping(value = "/latests")
	public List<PostVO> latests(@RequestParam(name = "size", defaultValue = "6") Integer size) {
		return postService.findLatests(size);
	}

	@RequestMapping(value = "/hots")
	public List<PostVO> hots(@RequestParam(name = "size", defaultValue = "6") Integer size) {
		return postService.findHottests(size);
	}

	@RequestMapping(value = "/latest_comments")
	public List<CommentVO> latestComments(@RequestParam(name = "size", defaultValue = "6") Integer size) {
		return commentService.findLatests(size);
	}

	@RequestMapping(value = "/stock")
	public List<StockVo> hotStock(@RequestParam(name = "size", defaultValue = "10") Integer size) {
		return stockService.findHotStock(size);
	}
}
